<template>
	<view>
		<view class="cu-form-group margin-top">
			<view class="title">规格选择</view>
			<picker @change="PickerChange" :value="index" :range="picker">
				<view class="picker">
					{{index>-1?picker[index]:'点击选择一款规格'}}
				</view>
			</picker>
		</view>
		<view>
			<uni-view data-v-0508c762="" class="cu-form-group margin-top">
				<uni-view data-v-0508c762="" class="title">价格￥：</uni-view>
				<view>{{this.price[this.index]}}</view>
			</uni-view>
		</view>
		<view>
			<uni-view data-v-0508c762="" class="cu-form-group margin-top">
				<uni-view data-v-0508c762="" class="title">请输入购买数量：</uni-view>
				<input  @input="recordName"/>
			</uni-view>
		</view>
		<view class="cu-form-group margin-top">
			<view class="title">收货地址</view>
			<picker @change="PickerChange1" :value="index1" :range="picker1">
				<view class="picker">
					{{index1>-1?picker1[index1]:'点击选择收货地址'}}
				</view>
			</picker>
		</view>
		<view >
			<uni-view data-v-6059f4d3="" class="margin-tb-sm text-center">
				<uni-button data-v-6059f4d3="" class="cu-btn round bg-red" @click="shopingNow">立即购买</uni-button>
			</uni-view>
		</view>
	</view>

</template>

<script>
	export default {
		onLoad:function(){
			// 从商品详情页获取的数据得出添加购物车需要的参数
			this.goodsSpecs=uni.getStorageSync("goodsSpecs");
			console.log(this.goodsSpecs);
			for(let i = 0;i<this.goodsSpecs.length;i++){
				this.goodsId=this.goodsSpecs[i].goodsId;
				this.specsId.push(this.goodsSpecs[i].goodsSpecsId);
				this.picker.push(this.goodsSpecs[i].goodsSpecs);
				this.price.push(this.goodsSpecs[i].goodsSpecsPrice);
			}
			// this.goodsSpecs.map(item=>{
			// 	this.goodsId=item.goodsId;
			// 	this.specsId.push(item.goodsSpecsId);
			// 	this.picker.push(item.goodsSpecs);
			// 	this.price.push(item.goodsSpecsPrice);
			// })
		},
		data() {
			return {
				goodsSpecs:[],
				goodsId:'',
				specsId:[],
				price:[],
				buyNumber:'',
				index: -1,
				picker: [],
				index1:-1,
				picker1: ['1', '2', '3'],
				list:[]
			}
		},
		methods: {
			PickerChange(e) {
				this.index = e.detail.value
			},
			PickerChange1(e) {
				this.index1 = e.detail.value
			},
			recordName(e){
				this.buyNumber=e.detail.value;
			},
			shopingNow(){
				this.list.push({
					specsId:this.specsId[this.index],
					goodsId:this.goodsId,
					addressId:this.picker1[this.index1],
					price:this.price[this.index],
					buyNumber:this.buyNumber
				}),
				this.$req.orderCommit(this.list).then(res=>{
					console.log(res);
					uni.navigateTo({
						url:'../pay/pay'
					}),
					uni.setStorageSync("tKey",res)
				})
				uni.removeStorageSync("goodsSpecs");
			}
		}
	}
</script>

<style>

</style>
